using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Markup;
using Common;
using Controls;
using SExperiment;

namespace MainView.StandardCurve
{
	public partial class UCStandardCurvePreview : UserControl, IComponentConnector
	{
		public static readonly DependencyProperty ProjectStdCurveProperty = DependencyProperty.Register("ProjectStdCurve", typeof(ProjectStdCurve), typeof(UCStandardCurvePreview), new UIPropertyMetadata(null, OnProjectStdCurveChanged));

		public ProjectStdCurve ProjectStdCurve
		{
			get
			{
				return (ProjectStdCurve)GetValue(ProjectStdCurveProperty);
			}
			set
			{
				SetValue(ProjectStdCurveProperty, value);
			}
		}

		private static void OnProjectStdCurveChanged(object sender, DependencyPropertyChangedEventArgs args)
		{
			UCStandardCurvePreview uCStandardCurvePreview = sender as UCStandardCurvePreview;
			if (uCStandardCurvePreview != null)
			{
				uCStandardCurvePreview.RefreshChart();
			}
		}

		public UCStandardCurvePreview()
		{
			InitializeComponent();
		}

		private void RefreshChart()
		{
			gridStdCurve.Children.Clear();
			if (ProjectStdCurve == null || ProjectStdCurve.ExternalTargetStdCurveList == null)
			{
				return;
			}
			base.Cursor = Cursors.Wait;
			if (ProjectStdCurve.ExternalTargetStdCurveList.Count == 1)
			{
				UCStandardCurveChart uCStandardCurveChart = new UCStandardCurveChart();
				uCStandardCurveChart.TargetStdCurve = ProjectStdCurve.ExternalTargetStdCurveList[0];
				gridStdCurve.Children.Add(uCStandardCurveChart);
			}
			else
			{
				TabControlEx tabControlEx = new TabControlEx();
				tabControlEx.Style = Utility.GetResource("TabControlStylesmall") as Style;
				foreach (TargetStdCurve externalTargetStdCurve in ProjectStdCurve.ExternalTargetStdCurveList)
				{
					TabItem tabItem = new TabItem();
					tabItem.Style = Utility.GetResource("TabItemStylesmall") as Style;
					tabItem.Header = externalTargetStdCurve.TargetName;
					tabItem.Content = new UCStandardCurveChart
					{
						TargetStdCurve = externalTargetStdCurve
					};
					tabControlEx.Items.Add(tabItem);
				}
				gridStdCurve.Children.Add(tabControlEx);
			}
			base.Cursor = Cursors.Arrow;
		}
	}
}
